using Basic.Traceability.Host.Api.Write;
using Basic.Traceability.Intrestructrue;
using Microsoft.EntityFrameworkCore;
using System.Reflection;
using Yitter.IdGenerator;
using NLog.Web;
using Basic.Traceability.Intrestructrue.Base;
using IGeekFan.AspNetCore.Knife4jUI;
using System.Net;
using ServiceManagement.Consul;
var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(p =>
{
    var path = Path.Combine(AppContext.BaseDirectory, "Basic.Traceability.Host.Api.Write.xml");
    p.IncludeXmlComments(path,true);
});

// 数据库
builder.Services.AddDbContext<MyDbContext>(x =>
{
    x.UseMySql(builder.Configuration.GetConnectionString("MySql"), new MySqlServerVersion("5.7"));
});
// MediatR
builder.Services.AddMediatR(cfg=>cfg.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly()));
// AutoMapper
builder.Services.AddAutoMapper(typeof(MyAutoMapper));
// 雪花ID
YitIdHelper.SetIdGenerator(new IdGeneratorOptions());
/// NLog
builder.Host.UseNLog();
builder.Configuration.Register();
// 仓储
builder.Services.AddScoped(typeof(IBaseRepository<>), typeof(BaseRepository<>));
var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    //app.UseSwaggerUI();
    app.UseKnife4UI();
}


// 启用静态文件服务
app.UseStaticFiles();

//跨域
app.UseCors(x => x.AllowAnyHeader().AllowAnyOrigin().AllowAnyMethod());
app.UseAuthorization();

app.MapControllers();

app.Run();
